/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GameArea.java
 *
 * Created on 10.08.2011, 10:28:16
 */

package knazzy.gui;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import javax.swing.JToolBar;
import knazzy.logic.DiceAnimation;
import knazzy.logic.DiceController;
import knazzy.logic.GameProcedure;

/**
 *
 * @author 76167
 */
public class GameArea extends javax.swing.JPanel {

    /** Creates new form GameArea */

    DiceController dc = new DiceController();
    GameProcedure gp = new GameProcedure();
    
    public GameArea() {
        initComponents();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;

        GradientPaint gp = new GradientPaint(0, 0, new Color(107,142,35).brighter(), this.getWidth()-100, this.getHeight(), new Color(179,238,58));
        g2.setPaint(gp);
        g2.fillRect(0, 0, this.getSize().width, this.getSize().height);
    }

    



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        lblPlayerB = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblNumberOfThrows = new javax.swing.JLabel();
        pnlDiceArea = new knazzy.gui.DiceArea();
        jSeparator2 = new javax.swing.JSeparator();
        btnThrow = new javax.swing.JButton();
        jToolBar1 = new KnazzyToolBar();
        btnNewGame = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        btnHighscore = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        btnAbout = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        lblPlayer1 = new javax.swing.JLabel();
        jSplitPane1 = new javax.swing.JSplitPane();

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setBackground(new java.awt.Color(0, 204, 0));

        lblPlayerB.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblPlayerB.setText("Player B");

        lblNumberOfThrows.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lblNumberOfThrows.setText("1. throw");

        pnlDiceArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btnThrow.setText("Throw!");
        btnThrow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThrowActionPerformed(evt);
            }
        });

        jToolBar1.setBorder(null);
        jToolBar1.setRollover(true);

        btnNewGame.setIcon(new javax.swing.ImageIcon(getClass().getResource("/knazzy/ressources/DiceIcon.png"))); // NOI18N
        btnNewGame.setToolTipText("New Game");
        btnNewGame.setFocusable(false);
        btnNewGame.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNewGame.setPreferredSize(new java.awt.Dimension(64, 64));
        btnNewGame.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnNewGame);
        jToolBar1.add(jSeparator4);

        btnHighscore.setIcon(new javax.swing.ImageIcon(getClass().getResource("/knazzy/ressources/HighscoreIcon.png"))); // NOI18N
        btnHighscore.setToolTipText("Highscores");
        btnHighscore.setFocusable(false);
        btnHighscore.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnHighscore.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnHighscore);
        jToolBar1.add(jSeparator5);

        btnAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/knazzy/ressources/AboutIcon.png"))); // NOI18N
        btnAbout.setToolTipText("About");
        btnAbout.setFocusable(false);
        btnAbout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAbout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAboutActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAbout);

        lblPlayer1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblPlayer1.setText("Player A");

        jSplitPane1.setBorder(null);
        jSplitPane1.setDividerLocation(262);
        jSplitPane1.setDividerSize(1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(108, 108, 108)
                .addComponent(pnlDiceArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblNumberOfThrows, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(440, Short.MAX_VALUE)
                .addComponent(btnThrow, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(441, Short.MAX_VALUE)
                .addComponent(lblPlayerB, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE))
                .addGap(0, 0, 0))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(lblPlayer1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(431, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPlayerB, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jSeparator1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 387, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlDiceArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNumberOfThrows, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnThrow)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(49, 49, 49)
                    .addComponent(lblPlayer1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(545, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnThrowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThrowActionPerformed
        
        //Set a random number between 1-6 to the 5 dices with a dice animation
        Thread t1 = new Thread(new DiceAnimation(pnlDiceArea.getPnlDice1()));
        Thread t2 = new Thread(new DiceAnimation(pnlDiceArea.getPnlDice2()));
        Thread t3 = new Thread(new DiceAnimation(pnlDiceArea.getPnlDice3()));
        Thread t4 = new Thread(new DiceAnimation(pnlDiceArea.getPnlDice4()));
        Thread t5 = new Thread(new DiceAnimation(pnlDiceArea.getPnlDice5()));

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();

        gp.setNumberOfThrows(gp.getNumberOfThrows()+1);

    }//GEN-LAST:event_btnThrowActionPerformed

    private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed
        AboutView av = new AboutView();
        av.setLocation((int)((Toolkit.getDefaultToolkit().getScreenSize().width/2)-(av.getSize().getWidth()/2)),
                (int)((Toolkit.getDefaultToolkit().getScreenSize().height/2)-(av.getSize().getHeight()/2)));
        av.setVisible(true);
    }//GEN-LAST:event_btnAboutActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAbout;
    private javax.swing.JButton btnHighscore;
    private javax.swing.JButton btnNewGame;
    private javax.swing.JButton btnThrow;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblNumberOfThrows;
    private javax.swing.JLabel lblPlayer1;
    private javax.swing.JLabel lblPlayerB;
    private knazzy.gui.DiceArea pnlDiceArea;
    // End of variables declaration//GEN-END:variables

}
